# create_time:  2021/5/18 11:05
from rest_framework import serializers
from .models import Area


class AreaSerializer(serializers.ModelSerializer):
    """省的序列化器"""

    class Meta:
        model = Area
        fields = ['id', 'name']


class SubsSerializer(serializers.ModelSerializer):
    """详情视图使用的序列化器"""
    subs = AreaSerializer(many=True)

    # subs = serializers.PrimaryKeyRelatedField()   # 只会序列化id
    # subs = serializers.StringRelatedField()   # 只会序列化模型中str方法返回值

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
